package com.company.OfferGuide;

import java.util.ArrayList;

public class 和为s的连续正数序列 {

    public int[][] findContinuousSequence(int target) {
        ArrayList<int []> lists = new ArrayList<>();


        for (int low = 1,right = 1,sum = 0; right < target; right++) {
            sum += right;
            while (sum > target) {
                sum -= low++;
            }
            if (sum == target) {
                int[] temp = new int[right - low + 1];
                for (int i = 0; i < temp.length; i++) {
                    temp[i] = low + i;
                }
                lists.add(temp);
            }
        }


        int[][] data = new int[lists.size()][];

        for (int i = 0; i < lists.size(); i++) {
            data[i] = lists.get(i);
        }

        return data;
    }

}
